package com.java.model.singleton;

/**
 * @author wangning
 * @create 2021-04-20 11:53
 */

public class TestSingleton02 {
	public static void main(String[] args) throws InterruptedException {
		Thread threadA = new Thread(new Runnable() {
			@Override
			public void run() {
				System.out.println("thread A start");
				System.out.println(SingletonImpl.INSTANCE);
			}

		});
		threadA.start();
		Thread.sleep(100);

		Thread threadB = new Thread(new Runnable() {
			@Override
			public void run() {
				System.out.println("thread B start");
				System.out.println(SingletonImpl.INSTANCE);
			}
		});
		threadB.start();
	}
	private static class SingletonImpl {
		private static final SingletonImpl INSTANCE = new SingletonImpl();
		private SingletonImpl() {
			System.out.println("constructor start.");
			try {
				Thread.sleep(10000);
			} catch (Exception e) {
				e.printStackTrace();
			}
			System.out.println("constructor end.");
		}
	}
}
